import java.util.HashMap;

public class HashTableDemo {

    public static void main(String[] args) {
        // initialize the hash table with capacity 10
        HashMap<String, Integer> hashTable = new HashMap<>(10);
        // add some key-value pairs to the hash table
        hashTable.put("apple", 10);
        hashTable.put("banana", 20);
        hashTable.put("orange", 30);
        // get the value of a key
        System.out.println(hashTable.get("banana")); // output: 20
        // check if a key exists in the hash table
        System.out.println(hashTable.containsKey("apple")); // output: true
        // remove a key-value pair from the hash table
        hashTable.remove("banana");
        // check if a key exists in the hash table after removal
        System.out.println(hashTable.containsKey("banana")); // output: false

        // print all key-value pairs in the hash table
        for (String key : hashTable.keySet()) {
            System.out.println(key + " : " + hashTable.get(key));
        }
        // java method reference
        hashTable.forEach(HashTableDemo::printKeyValuePair);
        // some other way to use method reference
        // java 8 lambda expression
        hashTable.forEach((key, value) -> System.out.println(key + " : " + value));
    }

    public static void printKeyValuePair(String key, Integer value)
    {
        System.out.println(key + " : " + value);
    }
}